import store from "../store"

/* 质朴长存法  by lifesinger */
// 用法：pad(2,3)输出"002",即补齐3位数，pad(223,2)输出"223"，没有影响
function pad(num, n) {
  var len = num.toString().length
  while (len < n) {
    num = "0" + num
    len++
  }
  return num
}

export function get_now_time_RFC3339() {
  // 这个函数获取现在的时间的RFC3339格式，形如：2019-03-18T10:58:37Z
  var myDate = new Date()
  return `${myDate.getFullYear()}-${pad(myDate.getMonth() + 1, 2)}-${pad(
    myDate.getDate(),
    2
  )}T${pad(myDate.getHours(), 2)}:${pad(myDate.getMinutes(), 2)}:${pad(
    myDate.getSeconds(),
    2
  )}`
}

export function graphql_request(data) {
  return {
    url: "/request",
    method: "post",
    headers: {
      "Content-Type": "application/graphql",
      "X-Todo-App-Auth": store.getters.getToken,
    },
    data,
  }
}
